package com.xm.zcf.dao.adminUser.impl;

import com.xm.zcf.dao.adminUser.AdminUserDao;
import com.xm.zcf.domain.adminuser.Adminuser;
import com.xm.zcf.domain.user.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/3/10.
 */
@Repository
public class AdminUserDaoImpl implements AdminUserDao{
    @Resource
    public SessionFactory sessionFactory;
    protected Session getSession(){
        Session session=sessionFactory.getCurrentSession();
        return  session;
    }
    @Override
    public List<User> findAllUser() {
        return getSession().createQuery("from Adminuser").list();
    }

    @Override
    public Adminuser findById(Integer id) {
       Adminuser adminuser=(Adminuser) getSession().createQuery("from Adminuser u where u.uid=?")
                .setParameter(0,id)
                .uniqueResult();
        return adminuser;
    }

    @Override
    public void deleteUser(Adminuser adminuser) {
        getSession().delete(adminuser);
    }
}
